<template>
  <div class="home">
            <el-container>
      <!-- 侧边栏 -->
      <el-aside width="auto">
        <div class="logo"></div>
        <el-menu
          :router="true"
          :default-active="$route.path"
          :unique-opened="true"
          :collapse="isCollapse"
          class="el-menu-admin"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b">
          <el-submenu index="InfMan">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>企业管理</span>
            </template>
            <el-menu-item index="/InfMan">
              <i class="el-icon-menu"></i>
              <span slot="title">信息管理</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="/ChFoEn">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>收费管理</span>
            </template>
            <el-menu-item index="/CaExQu">
              <i class="el-icon-menu"></i>
              <span slot="title">水电费信息</span>
            </el-menu-item>
            <el-menu-item index="/ChFoEn">
              <i class="el-icon-menu"></i>
              <span slot="title">其他费用</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="/CoRoAp">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>园区管理</span>
            </template>
            <el-menu-item index="/CoRoAp">
              <i class="el-icon-menu"></i>
              <span slot="title">会议室</span>
            </el-menu-item>
            <el-menu-item index="/CoRoApApply">
              <i class="el-icon-menu"></i>
              <span slot="title">会议室申请</span>
            </el-menu-item>
            <el-menu-item index="/Repair">
              <i class="el-icon-menu"></i>
              <span slot="title">故障报修</span>
            </el-menu-item>
            <el-menu-item index="/Rent">
              <i class="el-icon-menu"></i>
              <span slot="title">租赁备案</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="/InCoReg">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>商业服务</span>
            </template>
            <el-menu-item index="/InCoReg">
              <i class="el-icon-menu"></i>
              <span slot="title">工商注册</span>
            </el-menu-item>
            <el-menu-item index="/InCoCha">
              <i class="el-icon-menu"></i>
              <span slot="title">工商变更</span>
            </el-menu-item>
            <el-menu-item index="/TraReg">
              <i class="el-icon-menu"></i>
              <span slot="title">商标注册</span>
            </el-menu-item>
            <el-menu-item index="/Patent">
              <i class="el-icon-menu"></i>
              <span slot="title">专利申请</span>
            </el-menu-item>
            <el-menu-item index="/LegSer">
              <i class="el-icon-menu"></i>
              <span slot="title">法律服务</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="ParSer">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>园区服务</span>
            </template>
            <!-- <el-menu-item index="/ParSer">
              <i class="el-icon-menu"></i>
              <span slot="title">政策申报</span>
            </el-menu-item> -->
            <el-menu-item index="/ParSerlist">
              <i class="el-icon-menu"></i>
              <span slot="title">政策列表</span>
            </el-menu-item>
            <el-menu-item index="/EnvGre">
              <i class="el-icon-menu"></i>
              <span slot="title">环境绿化</span>
            </el-menu-item>
            <el-menu-item index="/DecSer">
              <i class="el-icon-menu"></i>
              <span slot="title">装修服务</span>
            </el-menu-item>
            <el-menu-item index="/ITCSer">
              <i class="el-icon-menu"></i>
              <span slot="title">IT云服务</span>
            </el-menu-item>
            <el-menu-item index="/Phone">
              <i class="el-icon-menu"></i>
              <span slot="title">宽带固话</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="Infor">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>资讯管理</span>
            </template>
            <el-menu-item index="/Infor">
              <i class="el-icon-menu"></i>
              <span slot="title">活动管理</span>
            </el-menu-item>
            <el-menu-item index="/news">
              <i class="el-icon-menu"></i>
              <span slot="title">新闻资讯</span>
            </el-menu-item>
            <el-menu-item index="/announcement">
              <i class="el-icon-menu"></i>
              <span slot="title">公告发布</span>
            </el-menu-item>
            <el-menu-item index="/slide_show">
              <i class="el-icon-menu"></i>
              <span slot="title">添加轮播图</span>
            </el-menu-item>
            <el-menu-item index="/merchants">
              <i class="el-icon-menu"></i>
              <span slot="title">招商信息</span>
            </el-menu-item>
            <el-menu-item index="/parkshows">
              <i class="el-icon-menu"></i>
              <span slot="title">园区展示</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <i class="myicon myicon-menu toggle-btn" prefix-icon="myicon myicon-key" @click="toggleCollapse"></i>
          <div class="system-title">智慧园区后台管理系统</div>
          <div>
            <span class="welcome">
              您好，admin
            </span>
            <el-dropdown>
              <span class="el-dropdown-link" >
                设置
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item  @click.native="logout">退出登录</el-dropdown-item>
                <el-dropdown-item @click.native="addDialogFormVisible=true">修改密码</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
        <!-- 添加用户对话框 -->
    <el-dialog title="修改密码" :visible.sync="addDialogFormVisible"  width="500px">
      <el-form :model="addForm" label-width="100px" :rules="rules" ref="addUserForm">
        <el-form-item label="当前密码:" prop="oldPwd">
          <el-input v-model="addForm.oldPwd" auto-complete="off" type="password"></el-input>
        </el-form-item>
        <el-form-item label="新密码:" prop="newPwd">
          <el-input v-model="addForm.newPwd" auto-complete="off" type="password"></el-input>
        </el-form-item>
        <el-form-item label="确认密码:" prop="newPwd1">
          <el-input v-model="addForm.newPwd1" auto-complete="off" type="password" @keyup.enter.native="addUserSubmit('addUserForm')"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addUserSubmit('addUserForm')" >确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    getUserList,
    Upassword
  } from "@/api";
  export default {
    data() {
      return {
        isCollapse: false,
        menuData: [],
        addDialogFormVisible: false,
        addForm: {
          newPwd: '',
          newPwd1:'',
          oldPwd:''
        },
        rules: {

        }
      }
    },
    methods: {
      handleOpen(key, keyPath) {
        console.log(key, keyPath)
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath)
      },
      toggleCollapse() {
        this.isCollapse = !this.isCollapse
      },
      logout() {
        // 清除登录状态，即保存在localStorage中的token
        localStorage.removeItem('mytoken')
        // 跳转到登录页面
        this.$router.push({
          name: 'Login'
        })
      },
            addUserSubmit(formName) {
         this.$refs[formName].validate(valide => {
          if (valide) {
            console.log(123213)
            console.log(this.addForm)
            Upassword(this.addForm).then(res => {
              console.log(res)
              if (res.status === 0) {
                this.$message({
                  type: 'success',
                  message: '修改密码成功    请重新登录！！！'
                })
                this.addDialogFormVisible = false
                setTimeout(() => {
                  localStorage.removeItem('mytoken')
                // 跳转到登录页面
                  this.$router.push({
                    name: 'Login'
                  })
                  }, 3000);
                  
              } else {
                this.$message({
                  type: 'warning',
                  message: res.message
                })
              }
              
            })
          }
        })
      },
    },
    mounted() {
      let params = {
        params: {
          query: '',
          pagenum: 1,
          pagesize: 1
        }
      }
      getUserList(params).then(res => {
        console.log(res)
      })
    }
  }

</script>
<style lang="scss" scoped>
  // .el-main{
  //   // padding: 0;
  //   background-image: url('../assets/welcome.png');
  //   background-size: 100% 100%
  // }
  .el-main {
    position: relative
  }
  .el-dropdown-link{
    color: #409EFF
  }
  .home {
    height: 100%;

    .el-menu-admin:not(.el-menu--collapse) {
      width: 200px;
      min-height: 60px;
      border-right:1px solid #3d445e
    }

    .el-container {
      height: 100%;
    }

    .el-aside {
      background-color: #545c64;
    }

    .el-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #545c64;
    }

    .logo {
      height: 56px;
      background: url(../assets/logo.png);
      background-size: 100% 100%;
      background-color: #989898;
    }

    .toggle-btn {
      font-size: 36px;
      color: #989898;
      cursor: pointer;
      line-height: 60px;
    }

    .system-title {
      font-size: 28px;
      color: white;
    }

    .welcome {
      color: white;
    }
  }

</style>
